<%@ page contentType="text/html;charset=UTF-8" %>

<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>学生档案修改界面</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div id="app" class="container">
    <div class="row">
        <div class="col-md-4"></div>
        <div class="col-md-4">
            <p class="h1 text-center">用户账户修改</p>
            <div>
                <input type="text"  class="form-control" placeholder="用户名"
                       v-model="result[0].name">
            </div>
            <br>
            <div>
                <input type="text"  class="form-control" placeholder="性别" v-model="result[0].sex">
            </div>
            <br>
            <div>
                <input type="text"  class="form-control" placeholder="班级" v-model="result[0].clazz">
            </div>
            <br>
            <div>
                <input type="text"  class="form-control" placeholder="出生日期" v-model="result[0].birth">
            </div>
            <br>
            <div>
                <input type="text"  class="form-control" placeholder="地址" v-model="result[0].address">
            </div>
            <br>
            <div>
                <input type="text"  class="form-control" placeholder="邮编" v-model="result[0].postalcode">
            </div>
            <br>
            <div>
                <input type="text"  class="form-control" placeholder="电话" v-model="result[0].phone">
            </div>
            <br>
            <div>
                <input type="text"  class="form-control" placeholder="入学日期" v-model="result[0].beginTime">
            </div>
            <br>
            <div>
                <input type="text"  class="form-control" placeholder="评价" v-model="result[0].remark">
            </div>
            <br>
            <button class="btn btn-info btn-block" @click="edit()">提交</button>
        </div>
        <div class="col-md-4">
        </div>
    </div>
</div>

<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            id:'',
            result:{},

        },
        methods:
            {
                getOne:function(){
                    $.ajax({
                        url: "/demo/stuInfo/getOne",
                        type: 'post',
                        data:{id:this.id},
                        dataType: 'json',
                        success:function (result) {

                            console.log("result---" + result[0].id);
                            app.result = result;
                            console.log("app.result--" + app.result[0])
                        }
                    })
                },
                edit: function () {
                    $.ajax({
                        url: "/demo/stuInfo/update",
                        type: 'post',
                        data: JSON.stringify(this.result[0]),
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (result) {
                            var url = '/demo/stuInfo/index';
                            if(result.indexOf("成功")>=0){
                                window.location.href='/demo/stuInfo/success?result=' + result + '&url=' + url;
                            }else{
                                window.location.href= '/demo/stuInfo/error?result=' + result + '&url=' + url;
                            }
                        },
                        error:function (result) {
                            console.log("error--" + app.result[0].stuId)
                            alert("请求失败!!")
                        }
                    })
                }
            }
    })
    $(function () {
        app.id = '${id}';
        app.getOne();
    })
</script>

</body>
</html>